package be.ac.ua.comp.projectGPT.biddingAgents;

//~--- non-JDK imports --------------------------------------------------------

import be.ac.ua.comp.projectGPT.auctions.Auction;
import be.ac.ua.comp.projectGPT.players.Consumer;
import be.ac.ua.comp.projectGPT.players.Person;
import be.ac.ua.comp.projectGPT.types.Type;


public abstract class BiddingAgent<T extends Type> extends Person {
    Auction<T>           auction;
    Consumer             consumer;
    long budget;
    String               name;

    public BiddingAgent(String name, Consumer consumer) {
        super(name);

        this.name = name;
        this.consumer = consumer;
    }

    public void result(Boolean result, long amount) {
        if(result) {
            consumer.win(auction.getProvider(), amount);
        } else {
            consumer.lose();
        }
    }

    public void start() {
        logger.info("Asking budget from consumer "+consumer.getName());
        budget =+ consumer.askBudget();
        logger.info("Received budget: "+budget);
    }

    public void setAuction(Auction<T> auction) {
        logger.info("Setting auction");

        this.auction = auction;
                consumer.setProvider(this, auction.getProvider());
    }

    public abstract long askBid(long currentBid);
}
